#include<iostream>
#include<string>
using namespace std;
const int N = 5e5 + 10;
int tr[N][26];
int e[N];
int n, m;
int idx;
void insert(string s)
{
	int cur=0;
	for (auto ch : s)
	{
		int path = ch - 'a';
		if (tr[cur][path] == 0) tr[cur][path] = ++idx;
		cur = tr[cur][path];
	}
	e[cur]++;

}
int find(string s)
{
	int cur = 0;
	for (auto ch : s)
	{
		int path = ch - 'a';
		if (tr[cur][path] == 0) return 0;
		cur = tr[cur][path];
	}

	if (e[cur] > 0)
	{
		int t = e[cur];
		e[cur] = -1;
		return t;
	}
	return e[cur];

}
int main()
{
	cin >> n;


	for (int i = 1;i <= n;i++)
	{
		string s;
		cin >> s;
		insert(s);
	}
	cin >> m;
	while (m--)
	{
		string s;
		cin >> s;
		int x = find(s);//注意一定要把这个值存起来，因为find函数不能重复调用
		if (x == 0)
		{
			cout << "WRONG" << endl;
		}
		else if(x<0)
		{
			cout << "REPEAT" << endl;
		}
		else cout << "OK" << endl;
	}
}